<!DOCTYPE html>
<html lang="en">
<head>
<title>SChannel helper: SChannel.SyncHandshake</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="generator" content="PasDoc 0.16.0">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel="StyleSheet" type="text/css" href="pasdoc.css">
</head>
<body>
<div class="container"><div class="navigation">
<h2><a href="index.html">SChannel helper</a></h2><ul><li><a href="AllUnits.html">Units</a></li><li><a href="ClassHierarchy.html">Class Hierarchy</a></li><li><a href="AllClasses.html">Classes, Interfaces, Objects and Records</a></li><li><a href="AllTypes.html">Types</a></li><li><a href="AllVariables.html">Variables</a></li><li><a href="AllConstants.html">Constants</a></li><li><a href="AllFunctions.html">Functions and Procedures</a></li><li><a href="AllIdentifiers.html">Identifiers</a></li></ul></div><div class="content">
<h1 class="unit">Unit SChannel.SyncHandshake</h1>
<div class="sections">
<div class="one_section"><a class="section" href="#PasDoc-Description">Description</a></div><div class="one_section">Uses</div><div class="one_section"><a class="section" href="#PasDoc-Classes">Classes, Interfaces, Objects and Records</a></div><div class="one_section"><a class="section" href="#PasDoc-FuncsProcs">Functions and Procedures</a></div><div class="one_section"><a class="section" href="#PasDoc-Types">Types</a></div><div class="one_section">Constants</div><div class="one_section">Variables</div></div>
<span id="PasDoc-Description"></span><h2 class="description">Description</h2>
<p>
Helper function that implements synchronous TLS handshake by means of Windows SChannel. The function is transport-agnostic so it could be applied to any socket implementation or even other transport.

<p>Inspired by <a href="http://www.coastrd.com/c-schannel-smtp">TLS-Sample</a>

<p>Uses <a href="https://jedi-apilib.sourceforge.net">JEDI API units</a>

<p>(c) Fr0sT-Brutal

<p>License MIT</p>
<span id="PasDoc-Uses"></span><h2 class="overview">Overview</h2>
<span id="PasDoc-Classes"></span><h3 class="cio">Classes, Interfaces, Objects and Records</h3>
<table class="classestable wide_list">
<tr class="listheader">
<th class="itemname">Name</th>
<th class="itemdesc">Description</th>
</tr>
<tr class="list">
<td class="itemname">Class&nbsp;<a class="bold" href="SChannel.SyncHandshake.EHandshakeCommError.html"><code>EHandshakeCommError</code></a></td>
<td class="itemdesc">Specific exception class raised by <a class="normal" href="SChannel.SyncHandshake.html#PerformClientHandshake">PerformClientHandshake</a> on communication failures.</td>
</tr>
</table>
<span id="PasDoc-FuncsProcs"></span><h3 class="summary">Functions and Procedures</h3>
<table class="summary wide_list">
<tr class="list">
<td class="itemcode"><code>procedure <strong><a href="SChannel.SyncHandshake.html#PerformClientHandshake">PerformClientHandshake</a></strong>(var SessionData: <a href="SChannel.Utils.TSessionData.html">TSessionData</a>; const ServerName: string; DebugLogFn: <a href="SChannel.Utils.html#TDebugFn">TDebugFn</a>; SendFn: <a href="SChannel.SyncHandshake.html#TSendFn">TSendFn</a>; RecvFn: <a href="SChannel.SyncHandshake.html#TRecvFn">TRecvFn</a>; out hContext: CtxtHandle; out ExtraData: TBytes);</code></td>
</tr>
</table>
<span id="PasDoc-Types"></span><h3 class="summary">Types</h3>
<table class="summary wide_list">
<tr class="list">
<td class="itemcode"><code><strong><a href="SChannel.SyncHandshake.html#TSendFn">TSendFn</a></strong> = function (Buf: Pointer; BufLen: Integer): Integer of object;</code></td>
</tr>
<tr class="list2">
<td class="itemcode"><code><strong><a href="SChannel.SyncHandshake.html#TRecvFn">TRecvFn</a></strong> = function (Buf: Pointer; BufLen: Integer): Integer of object;</code></td>
</tr>
</table>
<h2 class="description">Description</h2>
<h3 class="detail">Functions and Procedures</h3>
<table class="detail wide_list">
<tr class="list">
<td class="itemcode"><span id="PerformClientHandshake"></span><code>procedure <strong>PerformClientHandshake</strong>(var SessionData: <a href="SChannel.Utils.TSessionData.html">TSessionData</a>; const ServerName: string; DebugLogFn: <a href="SChannel.Utils.html#TDebugFn">TDebugFn</a>; SendFn: <a href="SChannel.SyncHandshake.html#TSendFn">TSendFn</a>; RecvFn: <a href="SChannel.SyncHandshake.html#TRecvFn">TRecvFn</a>; out hContext: CtxtHandle; out ExtraData: TBytes);</code></td>
</tr>
<tr><td colspan="1">
<p>
Synchronously perform full handshake process including communication with server. Communication is done via two callback functions.          <a class="normal" href="SChannel.SyncHandshake.EHandshakeCommError.html">EHandshakeCommError</a> on communication failure</p>
<h6 class="description_section">Parameters</h6>
<dl class="parameters">
<dt>SessionData</dt>
<dd>- [IN/OUT] record with session data</dd>
<dt>ServerName</dt>
<dd>- name of domain to connect to</dd>
<dt>DebugLogFn</dt>
<dd>- logging callback, could be <code>Nil</code></dd>
<dt>Data</dt>
<dd>- any data with which <code>SendFn</code> and <code>RecvFn</code> will be called</dd>
<dt>SendFn</dt>
<dd>- data send callback</dd>
<dt>RecvFn</dt>
<dd>- data read callback</dd>
<dt>hContext</dt>
<dd>- [OUT] receives current session context</dd>
<dt>ExtraData</dt>
<dd>- [OUT] receives extra data sent by server to be decrypted</dd>
</dl>
<h6 class="description_section">Exceptions raised</h6>
<dl class="exceptions_raised">
<dt><a class="normal" href="SChannel.Utils.ESSPIError.html">ESSPIError</a></dt>
<dd>on SChannel-related failure,</dd>
</dl>
</td></tr>
</table>
<h3 class="detail">Types</h3>
<table class="detail wide_list">
<tr class="list">
<td class="itemcode"><span id="TSendFn"></span><code><strong>TSendFn</strong> = function (Buf: Pointer; BufLen: Integer): Integer of object;</code></td>
</tr>
<tr><td colspan="1">
<p>
Synchronous communication method.    </p>
<h6 class="description_section">Parameters</h6>
<dl class="parameters">
<dt>Buf</dt>
<dd>- buffer with data</dd>
<dt>BufLen</dt>
<dd>- size of data in buffer</dd>
</dl>
<h6 class="description_section">Returns</h6>
<p class="return">amount of data sent if &gt;= 0 or error code if &lt; 0. Error code is used to log and create exception. FormatMessage is used to generate a string from error code. Must try to send all data in full, as no retries or repeated sends is done.</p><h6 class="description_section">Exceptions raised</h6>
<dl class="exceptions_raised">
<dt><code>exception</code></dt>
<dd>on some non-network error</dd>
</dl>
</td></tr>
</table>
<table class="detail wide_list">
<tr class="list">
<td class="itemcode"><span id="TRecvFn"></span><code><strong>TRecvFn</strong> = function (Buf: Pointer; BufLen: Integer): Integer of object;</code></td>
</tr>
<tr><td colspan="1">
<p>
Synchronous communication method.    </p>
<h6 class="description_section">Parameters</h6>
<dl class="parameters">
<dt>Buf</dt>
<dd>- buffer to receive data</dd>
<dt>BufLen</dt>
<dd>- size of free space in buffer</dd>
</dl>
<h6 class="description_section">Returns</h6>
<p class="return">amount of data received if &gt;= 0 or error code if &lt; 0. Error code is used to log and create exception. FormatMessage is used to generate a string from error code. Could receive only some of the data available as incomplete packet is read in loop</p><h6 class="description_section">Exceptions raised</h6>
<dl class="exceptions_raised">
<dt><code>exception</code></dt>
<dd>on some non-network error</dd>
</dl>
</td></tr>
</table>
<hr><span class="appinfo"><em>Generated by <a href="https://pasdoc.github.io/">PasDoc 0.16.0</a>. </em>
</span>
</div></div></body></html>
